//
//  MainLiveInPutTollBarAlertSendInfoView.m
//  v8090Video
//
//  Created by 陈建 on 2018/9/6.
//  Copyright © 2018年 BlueWind. All rights reserved.
//

#import "MainLiveInPutTollBarAlertSendInfoView.h"

#import "MainLiveInPutTollBarView.h"

@interface MainLiveInPutTollBarAlertSendInfoView ()<MainLiveInPutTollBarViewDelegate>

@property (nonatomic, strong) MainLiveInPutTollBarView *inputToolbar;
// 背景视图
@property (nonatomic, strong) UIView *backgroundView;
@end

@implementation MainLiveInPutTollBarAlertSendInfoView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupSubViews];
    }
    return self;
}

- (void)showInputView{
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    [keyWindow addSubview:self];
    
}

- (void)setupSubViews{
    [self addSubview:self.backgroundView];
    [self.backgroundView addSubview:self.inputToolbar];
     [self.inputToolbar.textInput becomeFirstResponder];
}

- (void)inputToolbar:(MainLiveInPutTollBarView *)inputToolbar sendContent:(NSString *)sendContent{
    [self dismissWithAnimation:YES];
    if (self.SendInfoTextBlock) {
        self.SendInfoTextBlock(sendContent);
    }
    if ([self.delegate respondsToSelector:@selector(sendInfoWithTextString:)]) {
        [self.delegate sendInfoWithTextString:sendContent];
    }
   
}


- (MainLiveInPutTollBarView *)inputToolbar{
    if (!_inputToolbar) {
        _inputToolbar = [[MainLiveInPutTollBarView alloc] initWithFrame:CGRectMake(0,self.backgroundView.height, self.width, 50)];
        _inputToolbar.textViewMaxLine = 5;
        _inputToolbar.delegate = self;
        _inputToolbar.placeholderLabel.text = @"说点什么吧···";
    }
    return _inputToolbar;
}
- (UIView *)backgroundView {
    if (!_backgroundView) {
        _backgroundView = [[UIView alloc]initWithFrame:self.bounds];
        _backgroundView.backgroundColor = [UIColor clearColor];
//        _backgroundView.userInteractionEnabled = YES;
        UITapGestureRecognizer *myTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapBackgroundView:)];
        [_backgroundView addGestureRecognizer:myTap];
    }
    return _backgroundView;
}
#pragma mark - 点击背景遮罩图层事件
- (void)didTapBackgroundView:(UITapGestureRecognizer *)sender {
    [self dismissWithAnimation:YES];
}

#pragma mark - 关闭视图方法
- (void)dismissWithAnimation:(BOOL)animation {
    if (self.WillBackViewDismiss) {
        self.WillBackViewDismiss();
    }
    [self removeFromSuperview];
    [self.inputToolbar removeFromSuperview];
    self.inputToolbar = nil;
}
@end
